Allow Python scalars as the search values in dpt.searchsorted#2225
Allow Python scalars as the search values in dpt.searchsorted#2225ndgrigorian wants to merge 5 commits intomasterfrom
dpt.searchsorted#2225Conversation
|
View rendered docs @ https://intelpython.github.io/dpctl/pulls/2225/index.html |
|
Array API standard conformance tests for dpctl=0.22.0dev0=py310h93fe807_104 ran successfully. |
b7de201 to
e85940e
Compare
|
Array API standard conformance tests for dpctl=0.22.0dev0=py310h93fe807_104 ran successfully. |
|
Array API standard conformance tests for dpctl=0.22.0dev0=py310h93fe807_105 ran successfully. |
|
Array API standard conformance tests for dpctl=0.22.0dev0=py310h93fe807_106 ran successfully. |
bda9809 to
b7c56e1
Compare
|
Array API standard conformance tests for dpctl=0.22.0dev0=py310h93fe807_106 ran successfully. |
|
|
||
| if not isinstance(x2, usm_ndarray): | ||
| x2 = dpt.asarray(x2, dtype=dt2, usm_type=res_usm_type, sycl_queue=q) | ||
| if x2.dtype != dt: |
There was a problem hiding this comment.
| if x2.dtype != dt: | |
| elif x2.dtype != dt: |
There was a problem hiding this comment.
this is not meant to be an elif. x2 is taken to dt2 first if not usm_ndarray then is cast to dt which is the resolved dtype. This way, it passes through dt2 under all circumstances.
There was a problem hiding this comment.
Then it's unclear for me, why do we need to run 2 kernels in that case?
- to convert a scalar to a temporary usm_ndarray and to copy back to the result
- to cast the array to
dt
What is a drawback to pass dt directly to asarray call?
There was a problem hiding this comment.
Also, in the sequence:
- cast
x1todt - cast
x2to usm_ndarray if any - cast
x2todt
We have to make step 2 as the 1st or as the last in the sequence, but not in the middle, because currently step 2 depends on events from step 1, but shouldn't.
And from other side, step 2 produces depending events which we must pass to step 3, but we didn't (asarray must be completed before we can start casting x2 to dt).
There was a problem hiding this comment.
Then it's unclear for me, why do we need to run 2 kernels in that case?
- to convert a scalar to a temporary usm_ndarray and to copy back to the result
- to cast the array to
dtWhat is a drawback to pass
dtdirectly toasarraycall?
with these Python scalars, it's what we've been doing in general (see: BinaryElementwiseFunc for example) and on top of this, it avoids possible undefined behavior. I can't immediately come up with examples, but it can be the case that
a = dpt.asarray(sc, dtype=dt)
is not necessarily the same as
tmp = dpt.asarray(sc, dtype=o_dt)
a = dpt.astype(tmp, dt)
but practically speaking we can reassess if any of these cases come up now that we've made some changes (like with unsigned ints)
There was a problem hiding this comment.
Also, in the sequence:
- cast
x1todt- cast
x2to usm_ndarray if any- cast
x2todtWe have to make step 2 as the 1st or as the last in the sequence, but not in the middle, because currently step 2 depends on events from step 1, but shouldn't. And from other side, step 2 produces depending events which we must pass to step 3, but we didn't (
asarraymust be completed before we can start castingx2todt).
great point, I'll adjust the dependency logic
|
Array API standard conformance tests for dpctl=0.22.0dev0=py310h93fe807_110 ran successfully. |
|
|
||
| if not isinstance(x2, usm_ndarray): | ||
| x2 = dpt.asarray(x2, dtype=dt2, usm_type=res_usm_type, sycl_queue=q) | ||
| if x2.dtype != dt: |
There was a problem hiding this comment.
Then it's unclear for me, why do we need to run 2 kernels in that case?
- to convert a scalar to a temporary usm_ndarray and to copy back to the result
- to cast the array to
dt
What is a drawback to pass dt directly to asarray call?
|
|
||
| if not isinstance(x2, usm_ndarray): | ||
| x2 = dpt.asarray(x2, dtype=dt2, usm_type=res_usm_type, sycl_queue=q) | ||
| if x2.dtype != dt: |
There was a problem hiding this comment.
Also, in the sequence:
- cast
x1todt - cast
x2to usm_ndarray if any - cast
x2todt
We have to make step 2 as the 1st or as the last in the sequence, but not in the middle, because currently step 2 depends on events from step 1, but shouldn't.
And from other side, step 2 produces depending events which we must pass to step 3, but we didn't (asarray must be completed before we can start casting x2 to dt).
This PR proposes permitting the search values of
dpt.searchsortedto be Python scalars, a change coming to the 2026 array API specResolves #2224